﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TroTro
{
    class SpeedGauge
    {
        #region Properties

        //Properties
        private readonly Game _game;
        private SpriteFont _font;
        private SpriteFont _fontSmall;
        private Vector2 _screenBounds;
        private Texture2D _gauge;

        #endregion

        #region constructor

        public SpeedGauge(Game game, Vector2 screenbounds)
        {
            _game = game;
            _screenBounds = screenbounds;
            LoadContent();
        }

        #endregion

        #region LoadContent

        public void LoadContent()
        {
            //Loads the content for the speed gauge
            _font = _game.Content.Load<SpriteFont>(@"Fonts\mph");
            _fontSmall = _game.Content.Load<SpriteFont>(@"Fonts\mphSmall");
            _gauge = _game.Content.Load<Texture2D>(@"sprites\MPHGauge\gauge");
        }

        #endregion

        #region Draw

        public void Draw(SpriteBatch spriteBatch, float roadSpeed, float speed)
        {
            //Draws the gauge to the screen
            spriteBatch.Draw(_gauge, new Rectangle(1030, 560, 180, 180), new Rectangle(0, 0, 350, 330), Color.White);

            //Draws speed to the screen
            spriteBatch.DrawString(_font, BuildString(roadSpeed + speed), new Vector2(_screenBounds.X - 130, 
                                                                     _screenBounds.Y - 90), Color.White);

            //Draws the MPH to the screen
            spriteBatch.DrawString(_fontSmall, "Mph", new Vector2(_screenBounds.X - 40, 
                                                                     _screenBounds.Y - 40), Color.White);
        }

        #endregion

        #region Build String

        public string BuildString(float speed)
        {
            return Convert.ToString(Convert.ToInt32(speed * 6F));
        }

        #endregion
    }
}
